package com.nine.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nine.demo.entity.UserContract;
import com.nine.demo.mapper.UserContractMapper;
import com.nine.demo.service.UserContractService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author nine
* @description 针对表【t_user_contract】的数据库操作Service实现
* @createDate 2024-08-06 22:18:44
*/
@Service
public class UserContractServiceImpl extends ServiceImpl<UserContractMapper, UserContract>
    implements UserContractService{

	@Override
	public boolean saveorUpdateContract(Integer uid, String bucketName, String originalFilename) {

		LambdaQueryWrapper<UserContract> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UserContract::getUid, uid);
		// 查询数据，没有则新增，有则修改
		UserContract userContract = this.getOne(wrapper);
		if (userContract == null) {
			userContract = new UserContract();
			userContract.setUid(uid);
			userContract.setBucket(bucketName);
			userContract.setObject(originalFilename);
			userContract.setCreateTime(new Date());
			return this.save(userContract);
		}
		else {
			userContract.setUpdateTime(new Date());
			return this.update(userContract, wrapper);
		}
	}

}




